package com.library.servlet.student;

import com.library.service.student.FineService;
import com.library.servlet.BaseServlet;
import com.library.entity.Student;
import com.library.util.StudentContext;

import javax.servlet.ServletException;
import javax.servlet.annotation.WebServlet;
import javax.servlet.http.HttpServletRequest;
import javax.servlet.http.HttpServletResponse;
import java.io.IOException;

@WebServlet("/student/fine/*")
public class FineServlet extends BaseServlet {
    private FineService fineService = new FineService();

    // 查看个人罚款情况
    protected void showFines(HttpServletRequest req, HttpServletResponse resp) throws ServletException, IOException {
        Student student = StudentContext.getStudent();
        String sno = student.getSno();
        String fineStatus = req.getParameter("fineStatus");
        req.setAttribute("fineStatus", fineStatus);
        req.setAttribute("fineList", fineService.getFineList(sno, fineStatus));
        req.getRequestDispatcher("/WEB-INF/student/showFines.jsp").forward(req, resp);
    }

    // 交罚款
    protected void payFine(HttpServletRequest req, HttpServletResponse resp) throws ServletException, IOException {
        Student student = StudentContext.getStudent();
        String sno = student.getSno();
        String serNum = req.getParameter("serNum");
        String resultMsg = fineService.payFine(serNum, sno);
        req.setAttribute("resultMsg", resultMsg);
        req.getRequestDispatcher("/WEB-INF/student/borrowResult.jsp").forward(req, resp);
    }
} 